﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLToolkit.DataAccess;
using BLToolkit.Data.Linq;
using BLToolkit.Mapping;

namespace Core
{
    [TableName("tblChucVu")]

    public class ChucVu
    {

        [PrimaryKey, Identity]
        [MapField("MaChucVu")]
        public int ID { get; set; }
        public string TenChucVu { get; set; }

        [Association(ThisKey = "MaChucVu", OtherKey = "MaChucVu", CanBeNull = true)]
        public List<CanBoChucVu> CanBoChucVus { get; set; }
        public static IQueryable<ChucVu> ChucVus
        {
            get
            {
                using (var db = new DataContext())
                {
                    return db.GetTable<ChucVu>();
                }
            }
        }
        public static List<ChucVu> All()
        {
            return ChucVus.ToList();
        }
        public static ChucVu Single(int id)
        {
            return ChucVus.SingleOrDefault(x => x.ID == id);
        }
        public static int Add(ChucVu entity)
        {
            using (var db = new DataContext())
            {
                object rs = db.InsertWithIdentity(entity);
                return int.Parse(rs.ToString());
            }
        }
        public static int Update(ChucVu entity)
        {
            using (var db = new DataContext())
            {
                return db.Update(entity);
            }
        }
        public static int Delete(int id)
        {
            return ChucVus.Delete(x => x.ID == id);
        }
    }
}
